<%@ page language="java" contentType="text/html;charset=utf-8"
	pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
	<script type="text/javascript" src="<%=path%>/js/ajaxupload.js"></script>
	
	<link rel="stylesheet" type="text/css" href="<%=path%>/jsplug/easyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="<%=path%>/jsplug/easyui/themes/icon.css">
	<link rel="stylesheet" type="text/css" href="<%=path%>/jsplug/easyui/demo/demo.css">
	<script type="text/javascript" src="<%=path%>/js/jquery.min.js"></script>
	<script type="text/javascript" src="<%=path%>/jsplug/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="<%=path%>/js/mytree.js"></script>
</head>
<body>
	<%@include file="header.jsp" %>
	
	<div id="container">
		<div id="main" class="fullscreen">
			<div class="content fl person">
				<div class="section panel-box hijackthis hijacked">
					<div class="blog-article-box">
						<div style="margin-top:5px;">
							<form id="field_form">
								<div style="float: left;margin-left: 24px;">
									<font style="">*属性映射设置(自定义属性名=淘宝属性名):</font>
									<select id="items_type" onchange="select_onchange_items(this)">
										<option value="default">请选择商品类别</option>
										<option value="50011153">背心/马甲</option>
										<option value="50000436">T恤</option>
										<option value="50010402">Polo衫</option>
										<option value="50000557">针织衫/毛衣</option>
										<option value="50010167">牛仔裤</option>
									</select>
									<select id="items_mapping" onchange="select_onchange(this)">
										<option value="default">请选择映射文件</option>
										<option value="filedMapping_custom.properties">用户字段映射</option>
										<option value="filedMapping_taobao.properties">淘宝字段映射</option>
										<option value="filedNotMapping.properties">不做映射字段</option>
										<option value="excel_custom_default.properties">excel配置</option>
										<option value="filedNotMapping - 2.properties">测试</option>
									</select>
									<font id="select_msg" color="red"></font>
								</div>
								<div align="right"><a href="#" onclick="save()">保存</a><div>
								<input type="hidden" name="filename" />
								<textarea id="field_textarea_form" name="field_textarea" style="display: none"></textarea>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
		
		<div id="testDiv" style="float:left;;margin-left:5%;margin-right:50px;">
			<textarea id="custom_mapping" rows="30" cols="30" ></textarea>
		</div>	
		<div id="mapping-div" style="height: auto;float:left;"></div>
		
	</div>
	<script type="text/javascript">
		$(function(){
			$("#items_mapping").val("filedMapping_custom.properties");
			select_onchange(document.getElementById("items_mapping"));
		});
		function save(){
			$("#field_textarea_form").val($("#custom_mapping").val());
			$.post("<%=path%>/Handler_saveMapping",
					$("#field_form").serialize(),
			        function(data, textStatus){
				  		if(data.status){
				  			alert("操作成功!" );
				  			query();
				  		}
					},"json");
		}
		function query(){
			$.post("<%=path%>/Handler_queryMapping",
					$("#field_form").serialize(),
			        function(data, textStatus){
			  			 $("#custom_mapping").val(data.context.replace(new RegExp("<br/>","gm"),"\r\n"));
					},"json");
		}
		function select_onchange(target){
			$("#custom_mapping").val("");
			var selectV = target.options[target.selectedIndex].value;
			$("#select_msg").text("当前配置文件为：" +　target.options[target.selectedIndex].text);
			if(selectV != "default"){
				$("input[name=filename]").val(target.options[target.selectedIndex].value);
				query();
			}else{
				$("#custom_mapping").val("");
			}
		}
		function select_onchange_items(target){
			var selectV = target.options[target.selectedIndex].value;
			$("#mapping-div").load("tree2.jsp?", {"file":selectV+".xml"}, function() {});
		}
	</script>
	
</body>
</html>